package com.parsechina.hpush.common.mybatis;

import org.mybatis.generator.api.IntrospectedTable;
import org.mybatis.generator.api.PluginAdapter;
import org.mybatis.generator.api.dom.java.FullyQualifiedJavaType;
import org.mybatis.generator.api.dom.java.Interface;
import org.mybatis.generator.api.dom.java.TopLevelClass;

import java.util.List;

/**
 * @author linfeng
 * @date 2018/4/19
 */
public class MapperMethodAnnotationPlugin extends PluginAdapter {

    private FullyQualifiedJavaType mapperAnnotation;

    public MapperMethodAnnotationPlugin() {
        this.mapperAnnotation = new FullyQualifiedJavaType("org.apache.ibatis.annotations.Mapper");
    }

    @Override
    public boolean validate(List<String> warnings) {
        return true;
    }


    @Override
    public boolean clientGenerated(Interface interfaze, TopLevelClass topLevelClass, IntrospectedTable introspectedTable) {

        interfaze.addImportedType(mapperAnnotation);
        interfaze.addAnnotation("@Mapper");

        return true;
    }
}
